/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#ifndef INCLUDE_GEOMETRY
#define INCLUDE_GEOMETRY

#include <basic_vec.h>



Inline bool f_geom_包围盒碰撞(const S_Bounding2D& box0, const S_Bounding2D& box1) {
	if (box1.min.x > box0.max.x) return false;
	if (box1.min.y > box0.max.y) return false;
	if (box1.max.x < box0.min.x) return false;
	if (box1.max.y < box0.min.y) return false;

	return true;
}

Inline vec3 f_geom_包围盒最小坐标(const S_Cube& 包围盒, const vec3& 单元大小) {
	vec3 pos = 包围盒.pos - 包围盒.size * 0.5f;
	if (pos.x < 0) pos.x -= 单元大小.x;
	if (pos.y < 0) pos.y -= 单元大小.y;
	if (pos.z < 0) pos.z -= 单元大小.z;
	//pos = (pos - 单元大小);
	ivec3 index = _iVec3(pos / 单元大小);
	return 单元大小 * index;
	//return 包围盒.pos - 包围盒.size * 0.5;
}

Inline void f_geom_包围盒最小坐标(const S_CubeArray* 包围盒, const S_Vec3Array* 单元大小, S_Vec3Array* 最小坐标) {
	uint32 num = DEF_Max(包围盒->count, 单元大小->count);
	bool 包围盒多例 = 包围盒->count >= num;
	bool 单元大小多例 = 单元大小->count >= num;

	f_core_array_resize((S_Array*)最小坐标, num);

	for (uint32 i = 0; i < num; ++i) {
		vec3 c = f_geom_包围盒最小坐标(包围盒多例 ? 包围盒->ptr_userData[i] : 包围盒->ptr_userData[0]
			, 单元大小多例 ? 单元大小->ptr_userData[i] : 单元大小->ptr_userData[0]);

		最小坐标->ptr_userData[i] = c;
	}
}




//Inline bool f_geom_VecCmo(S_Vec3Array* v1, S_Vec3Array* v2, S_Vec3Array* r, int32 方式) {
//	uint32 num = DEF_Max(v1->count, v2->count);
//
//	f_core_array_resize((S_Array*)r, num);
//	vec3* p_outData = r->ptr_userData;
//
//	bool 插座1单例 = v1->count < num;
//	bool 插座2单例 = v2->count < num;
//
//	vec3* p_data1 = v1->ptr_userData;
//	vec3* p_data2 = v2->ptr_userData;
//
//	S_UI32Array* v1Index = f_core_array_Index((S_Array*)v1);
//	S_UI32Array* v2Index = f_core_array_Index((S_Array*)v2);
//
//
//	f_omp_set_threadsNum(DEF_Min(16, num));
//	switch (方式) {
//		case 0: {
//	#pragma omp parallel for
//			for (int64 i = 0; i < num; ++i) {
//				p_outData[i] = vec_add(插座1单例 ? p_data1[0] : p_data1[i], 插座2单例 ? p_data2[0] : p_data2[i]);
//			}
//			break;
//		}
//		case 1: {
//	#pragma omp parallel for
//			for (int64 i = 0; i < num; ++i) {
//				p_outData[i] = vec_sub(插座1单例 ? p_data1[0] : p_data1[i], 插座2单例 ? p_data2[0] : p_data2[i]);
//			}
//			break;
//		}
//		case 2: {
//	#pragma omp parallel for
//			for (int64 i = 0; i < num; ++i) {
//				p_outData[i] = vec_mul(插座1单例 ? p_data1[0] : p_data1[i], 插座2单例 ? p_data2[0] : p_data2[i]);
//			}
//			break;
//		}
//		case 3: {
//	#pragma omp parallel for
//			for (int64 i = 0; i < num; ++i) {
//				p_outData[i] = vec_div(插座1单例 ? p_data1[0] : p_data1[i], 插座2单例 ? p_data2[0] : p_data2[i]);
//			}
//			break;
//		}
//		case 4: {
//	#pragma omp parallel for
//			for (int64 i = 0; i < num; ++i) {
//				p_outData[i] = cross(插座1单例 ? p_data1[0] : p_data1[i], 插座2单例 ? p_data2[0] : p_data2[i]);
//			}
//			break;
//		}
//	}
//
//	return true;
//}






#endif //INCLUDE_GEOMETRY


